﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_shgl_stuinfo1 : System.Web.UI.Page
{
    DataClassesDataContext db = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ShowInfo();
        }
    }
    private void ShowInfo()
    {
        string wbh = Request.QueryString["wbh"].ToString();
        int flag = Convert.ToInt32(Request.QueryString["flag"].ToString());
        if (flag == 1)
        {
            MultiView1.SetActiveView(View1);
            Panel1.Visible = true;
        }
        else if(flag == 2)
        {
            MultiView1.SetActiveView(View1);
            Panel2.Visible = true;
        }
        else if (flag == 3)
        {
            MultiView1.SetActiveView(View2);
            Panel4.Visible = true;
        }
        else if (flag == 4)
        {
            MultiView1.SetActiveView(View2);
            Panel3.Visible = true;
        }

        var resNation = from p in db.proc_GetNation()
                        select p;
        var resPolitics = from p in db.proc_GetPolitics()
                          select p;
        var result = (from p in db.proc_GetStuInfoBywbh(wbh)
                      select p).ToList().First();
        Image2.ImageUrl = "~/Student/stuimage" + result.sidfy + ".jpg";
        TextBox3.Text = result.sname;
        DropDownList1.SelectedValue = result.ssex;
        DropDownList2.SelectedValue = result.snation == null ? null : result.snation;
        string S = result.sbirth;
        if (S != null)
            Label3.Text = S.Substring(0, 4) + "年" + S.Substring(4, 2) + "月" + S.Substring(6, 2) + "日";
        Label4.Text = result.sidfy;
        DropDownList3.SelectedValue = result.sps;
        TextBox4.Text = result.gkbmh;
        TextBox5.Text = result.sdept;
        TextBox6.Text = result.byzy;
        if (result.schoolCode != "" && result.schoolCode != null)
        {
            DropDownList5.SelectedValue = result.schoolCode;
        }
        DropDownList4.SelectedValue = result.proNum;
        Label5.Text = result.proNum;
        TextBox1.Text = result.getaward;
        TextBox2.Text = result.advantage;
        TextBox8.Text = result.haddress;
        Label6.Text = result.sphone;
        TextBox9.Text = result.lxaddress;
        TextBox10.Text = result.postcode;

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string wbh = Request.QueryString["wbh"].ToString();
        studentInformation stuRes = db.studentInformation.First(c => c.wbh == wbh);
        stuRes.zKZflag = 0;
        db.SubmitChanges();
        ClientScript.RegisterClientScriptBlock(this.GetType(), "success", "<script>alert('审核通过！');window.location='shgl.aspx'</script>");
    }

    private int Save()
    {
        string wbh = Request.QueryString["wbh"].ToString();
        string Syear = System.DateTime.Today.ToString().Substring(0, 4);
        try
        {
            if ((db.proc_UpdateStuInfoBywbh(wbh, DropDownList4.SelectedValue, TextBox3.Text.Trim(), DropDownList1.SelectedValue, TextBox3.Text.Trim(), DropDownList5.SelectedValue, TextBox6.Text.Trim(), TextBox10.Text.Trim(), TextBox9.Text.Trim(), TextBox2.Text, TextBox1.Text, DropDownList2.SelectedValue, DropDownList3.SelectedValue, TextBox5.Text.Trim(), TextBox8.Text.Trim(), Syear)) == -1)
            {
                return -1;
            }
            db.SubmitChanges();

        }
        catch
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "error", "<script>alert('保存失败，请重试！')</script>");
        }
        return 1;
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        int flag = Save();
        if (flag == -1)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "error", "<script>alert('保存失败，请重试！')</script>");
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "error", "<script>alert('保存成功！')</script>");
            ShowInfo();
        }
    }
    private int UpdateAuditSuccess(int proflag)
    {
        string wbh = Request.QueryString["wbh"].ToString();
        if ((db.proc_UpdateStuProFlagBywbh(wbh, proflag)) == -1)
        {
            return -1;
        }
        else
        {
            return 1;
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string wbh = Request.QueryString["wbh"].ToString();
        try
        {
            if (UpdateAuditSuccess(3) == -1)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "success", "<script>alert('操作失败！')</script>");
            }
            else
            {
                studentInformation stuRes =
                db.studentInformation.First(c => c.wbh == wbh);
                stuRes.zKZflag = 1;
                db.SubmitChanges();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "success", "<script>alert('审核预通过！');window.location='shgl.aspx'</script>");
            }
        }
        catch
        {

        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (UpdateAuditSuccess(4) == -1)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "error", "<script>alert('操作失败！')</script>");
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "error", "<script>alert('审核不通过！');window.location='shgl.aspx'</script>");
        }
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        string wbh = Request.QueryString["wbh"].ToString();
        if ((db.proc_UpdateStuProFlagBywbh(wbh, 2)) == -1)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "success", "<script>alert('操作失败！')</script>");
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "success", "<script>alert('返回待审核状态成功！');window.location='shgl.aspx'</script>");
        }
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        Response.Redirect("shgl.aspx");
    }
}